/**
 */
package br.ufrn.dimap.ase.squid.core.models.squidmodel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import br.ufrn.dimap.ase.squid.core.models.squidmodel.CodePiece;
import br.ufrn.dimap.ase.squid.core.models.squidmodel.SquidmodelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Code Piece</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link squidmodel.impl.CodePieceImpl#getCodePieces <em>Code Pieces</em>}</li>
 *   <li>{@link squidmodel.impl.CodePieceImpl#getStart <em>Start</em>}</li>
 *   <li>{@link squidmodel.impl.CodePieceImpl#getEnd <em>End</em>}</li>
 *   <li>{@link squidmodel.impl.CodePieceImpl#getFirstLine <em>First Line</em>}</li>
 *   <li>{@link squidmodel.impl.CodePieceImpl#getLastLine <em>Last Line</em>}</li>
 *   <li>{@link squidmodel.impl.CodePieceImpl#getCode <em>Code</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class CodePieceImpl extends AssetImpl implements CodePiece {
	/**
	 * The cached value of the '{@link #getCodePieces() <em>Code Pieces</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCodePieces()
	 * @generated
	 * @ordered
	 */
	protected EList<CodePiece> codePieces;

	/**
	 * The default value of the '{@link #getStart() <em>Start</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStart()
	 * @generated
	 * @ordered
	 */
	protected static final int START_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getStart() <em>Start</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStart()
	 * @generated
	 * @ordered
	 */
	protected int start = START_EDEFAULT;

	/**
	 * The default value of the '{@link #getEnd() <em>End</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEnd()
	 * @generated
	 * @ordered
	 */
	protected static final int END_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getEnd() <em>End</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEnd()
	 * @generated
	 * @ordered
	 */
	protected int end = END_EDEFAULT;

	/**
	 * The default value of the '{@link #getFirstLine() <em>First Line</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFirstLine()
	 * @generated
	 * @ordered
	 */
	protected static final int FIRST_LINE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getFirstLine() <em>First Line</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFirstLine()
	 * @generated
	 * @ordered
	 */
	protected int firstLine = FIRST_LINE_EDEFAULT;

	/**
	 * The default value of the '{@link #getLastLine() <em>Last Line</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLastLine()
	 * @generated
	 * @ordered
	 */
	protected static final int LAST_LINE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getLastLine() <em>Last Line</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLastLine()
	 * @generated
	 * @ordered
	 */
	protected int lastLine = LAST_LINE_EDEFAULT;

	/**
	 * The default value of the '{@link #getCode() <em>Code</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCode()
	 * @generated
	 * @ordered
	 */
	protected static final String CODE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getCode() <em>Code</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCode()
	 * @generated
	 * @ordered
	 */
	protected String code = CODE_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected CodePieceImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SquidmodelPackage.Literals.CODE_PIECE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<CodePiece> getCodePieces() {
		if (codePieces == null) {
			codePieces = new EObjectContainmentEList<CodePiece>(CodePiece.class, this, SquidmodelPackage.CODE_PIECE__CODE_PIECES);
		}
		return codePieces;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getStart() {
		return start;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStart(int newStart) {
		int oldStart = start;
		start = newStart;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SquidmodelPackage.CODE_PIECE__START, oldStart, start));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getEnd() {
		return end;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEnd(int newEnd) {
		int oldEnd = end;
		end = newEnd;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SquidmodelPackage.CODE_PIECE__END, oldEnd, end));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getFirstLine() {
		return firstLine;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFirstLine(int newFirstLine) {
		int oldFirstLine = firstLine;
		firstLine = newFirstLine;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SquidmodelPackage.CODE_PIECE__FIRST_LINE, oldFirstLine, firstLine));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getLastLine() {
		return lastLine;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLastLine(int newLastLine) {
		int oldLastLine = lastLine;
		lastLine = newLastLine;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SquidmodelPackage.CODE_PIECE__LAST_LINE, oldLastLine, lastLine));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getCode() {
		return code;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCode(String newCode) {
		String oldCode = code;
		code = newCode;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SquidmodelPackage.CODE_PIECE__CODE, oldCode, code));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SquidmodelPackage.CODE_PIECE__CODE_PIECES:
				return ((InternalEList<?>)getCodePieces()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SquidmodelPackage.CODE_PIECE__CODE_PIECES:
				return getCodePieces();
			case SquidmodelPackage.CODE_PIECE__START:
				return getStart();
			case SquidmodelPackage.CODE_PIECE__END:
				return getEnd();
			case SquidmodelPackage.CODE_PIECE__FIRST_LINE:
				return getFirstLine();
			case SquidmodelPackage.CODE_PIECE__LAST_LINE:
				return getLastLine();
			case SquidmodelPackage.CODE_PIECE__CODE:
				return getCode();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SquidmodelPackage.CODE_PIECE__CODE_PIECES:
				getCodePieces().clear();
				getCodePieces().addAll((Collection<? extends CodePiece>)newValue);
				return;
			case SquidmodelPackage.CODE_PIECE__START:
				setStart((Integer)newValue);
				return;
			case SquidmodelPackage.CODE_PIECE__END:
				setEnd((Integer)newValue);
				return;
			case SquidmodelPackage.CODE_PIECE__FIRST_LINE:
				setFirstLine((Integer)newValue);
				return;
			case SquidmodelPackage.CODE_PIECE__LAST_LINE:
				setLastLine((Integer)newValue);
				return;
			case SquidmodelPackage.CODE_PIECE__CODE:
				setCode((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SquidmodelPackage.CODE_PIECE__CODE_PIECES:
				getCodePieces().clear();
				return;
			case SquidmodelPackage.CODE_PIECE__START:
				setStart(START_EDEFAULT);
				return;
			case SquidmodelPackage.CODE_PIECE__END:
				setEnd(END_EDEFAULT);
				return;
			case SquidmodelPackage.CODE_PIECE__FIRST_LINE:
				setFirstLine(FIRST_LINE_EDEFAULT);
				return;
			case SquidmodelPackage.CODE_PIECE__LAST_LINE:
				setLastLine(LAST_LINE_EDEFAULT);
				return;
			case SquidmodelPackage.CODE_PIECE__CODE:
				setCode(CODE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SquidmodelPackage.CODE_PIECE__CODE_PIECES:
				return codePieces != null && !codePieces.isEmpty();
			case SquidmodelPackage.CODE_PIECE__START:
				return start != START_EDEFAULT;
			case SquidmodelPackage.CODE_PIECE__END:
				return end != END_EDEFAULT;
			case SquidmodelPackage.CODE_PIECE__FIRST_LINE:
				return firstLine != FIRST_LINE_EDEFAULT;
			case SquidmodelPackage.CODE_PIECE__LAST_LINE:
				return lastLine != LAST_LINE_EDEFAULT;
			case SquidmodelPackage.CODE_PIECE__CODE:
				return CODE_EDEFAULT == null ? code != null : !CODE_EDEFAULT.equals(code);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (Start: ");
		result.append(start);
		result.append(", End: ");
		result.append(end);
		result.append(", FirstLine: ");
		result.append(firstLine);
		result.append(", LastLine: ");
		result.append(lastLine);
		result.append(", Code: ");
		result.append(code);
		result.append(')');
		return result.toString();
	}

} //CodePieceImpl
